﻿Imports System.Data.OleDb

Public Class Gallery
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Protected Sub btnsubmit_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnsubmit.Click
        Dim myGUID = Guid.NewGuid()
        Dim newFileName As String = myGUID.ToString() & ".jpg"
        If txtImage.HasFile Then
            Dim fileLocationOnDisk = Request.MapPath("Images/CarImages") & "/" & newFileName
            txtImage.SaveAs(fileLocationOnDisk)
        End If
        Dim sql As String = "INSERT INTO Images (ImageLink,ImageDescription,DateUploaded,TimeUploaded,UserIDFK) VALUES (@f1,@f2,@f3,@f4,@f5)"
        Dim conn As OleDbConnection = New OleDbConnection(ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString)
        Dim cmd As OleDbCommand = New OleDbCommand(sql, conn)
        cmd.Parameters.AddWithValue("@f1", "Images/CarIMages/" & newFileName)
        cmd.Parameters.AddWithValue("@f2", txtimagedescription.Text)
        cmd.Parameters.AddWithValue("@f3", Now.Date.ToString("dd/MM/yyyy"))
        cmd.Parameters.AddWithValue("@f4", DateTime.Now.ToString("t"))
        cmd.Parameters.AddWithValue("@f5", Membership.GetUser(User.Identity.Name).ProviderUserKey)
        conn.Open()
        cmd.ExecuteNonQuery()
        conn.Close()
        cmd.Dispose()
        conn.Dispose()
        Response.Redirect("Gallery.aspx")

    End Sub
End Class